<?
/************code by seven****************/
require("../../common/init.php");
require("author.php");
require("upfile.php");

$gee=$score_card; // gee, 意为赶车时候喊的"驾", 此处用来表示次页面的主角对象

$url='score_card';
$s=isset($_GET["s"])?clean($_GET["s"]):''; // search
$do=isset($_GET["do"])?clean($_GET["do"]):'view'; // 操作: 查看/编辑/删除
$action=isset($_POST["action"])?clean($_POST["action"]):''; // 数据库操作: CURD
$id=0; if (isset($_GET["id"])) $id = clean($_GET["id"]);

$filter="0";
if(isset($_GET["filter"]))$filter=clean($_GET["filter"]);
if(isset($_POST["filter"]))$filter=clean($_POST["filter"]);

switch ($filter){
    case 0:
        $title=ROOT_SCORE_CARD_LIST;
        break;
    case 1:
        $title=ROOT_PAID_ORDER_LIST;
        break;
    case 2:
        $title=ROOT_PENDING_SHIPMENT_ORDER_LIST;
        break;
    case 3:
        $title=ROOT_SHIPPED_ORDER_LIST;
        break;
    case 4:
        $title=ROOT_DELIVERED_ORDER_LIST;
        break;
    case 5:
        $title=ROOT_REFUNDED_ORDER_LIST;
        break;
    default:
        $title=ROOT_ORDER_LIST;
}

// sql action / sql 动作
switch ($action){
    case "update":
        sql_update();
        break;
    case "add":
        sql_insert();
        break;
}

if($id==0){
    $page=1; if(isset($_GET["page"]))if(is_numeric($_GET["page"]))$page=$_GET["page"];
    $order='end_time';
    $where=array();
    if($filter != '') {
        if($filter == 0){}
        $where[]=array('name'=>'is_used','val'=>$filter,'opn'=>'=', 'and'=>'and');
    }
    if($s!='') {
        $where[]=array('name'=>'number','val'=>$s,'opn'=>'like', 'and'=>'and', 'start'=>'(', 'end'=>')');
    }
    $pages=$gee->count_pages($where);
    $info=$gee->get_page($page,$where,$order);
}
else $info=$gee->get_row($id);


function add()
{
    global $h, $url;
    $row = array(
    );
    echo $h->form($url.'.php', 1, '');
    show_box($row, true, true);
    echo $h->hidden('action', 'add');
    echo $h->former();
}
function update($info)
{
    global $gee, $h, $url, $id;
    if($id=="")
    {
        echo "Invali argument!!!";
        exit;
    }
    echo $h->form($url.'.php', 1, '');
    show_box($info, true, false);
    echo $h->hidden('action', 'update');
    echo $h->former();
}
function delete($id)
{
    global $gee,$url;
    $picdir=ROOT.'upload/';
    $info=$gee->get_row($id);
    $oldpic=$picdir.$info['pic'];
    if($gee->delete($id)){
        @unlink($oldpic);
        wheel("$url.php");
    }
}
function show_info($info)
{
    global $id;
    if($id==0)
    {
        show_boxes($info);
    }
    else
    {
        show_box($info, false);
    }
}
function sql_insert()
{
    global $gee,$url,$arrlang;
    $arr=array(
        'number'=>$_POST["number"],
        'pwd'=>$_POST["pwd"],
        'score'=>$_POST["score"],
        'create_time'=>date('Y-m-d H:i:s', time()),
        'start_time'=>$_POST["start_time"],
        'end_time'=>$_POST["end_time"],
        'user_id'=>$_COOKIE['user_id'],
    );
    //pre($arr); exit;
    if($gee->insert($arr))
        yell(ROOT_ADD_SUCCESS,$url.'.php');
}
function sql_update()
{
    global $gee, $url,$arrlang;
    $candelete=0;
    $picdir=ROOT.'upload/';
    $id=$_POST["id"];
    $arr=array(
        'number'=>$_POST["number"],
        'pwd'=>$_POST["pwd"],
        'score'=>$_POST["score"],
        'start_time'=>$_POST["start_time"],
        'end_time'=>$_POST["end_time"],
        'user_id'=>$_COOKIE['user_id'],
    );
    //pre($arr); exit;
    if($gee->update($arr, 'id', $id ) ) {
        yell(ROOT_UPDATE_SUCCESS,$url.'.php');
    }
}

// view 加载视图
require ROOTVIEW.$url.'.php';

// end article.php
